package com.sss.myspringsecurity.websocketcontroller;

import com.alibaba.fastjson.JSON;
import com.sss.myspringsecurity.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author sss
 * @date 2020-02-17 20:48
 **/
@RestController
@RequestMapping("/websocket")
public class TestController {
    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate;

    @PostMapping("/user/message")
    public Result sendUserMessage(HelloMessage message){
        String string = JSON.toJSONString(message);
        simpMessagingTemplate.convertAndSendToUser(message.getUsername(),"/one",string);
        return Result.succes();
    }

}
